// pages/register/register2.js
var http = require('../common/service/http.js');
var kvutil = require('../common/service/kvutil.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    formData: {
      account: {
        title: "会员账号",
        holder: "",
        key: "account",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          minLength: "4"
        }
      },
      mobile: {
        title: "手机",
        holder: "",
        key: "mobile",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: false,
        isRequired: true,
        requiredRule: {
          length: "11"
        }
      },
      password: {
        title: "密码",
        holder: "",
        key: "password",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          minLength: "6"
        }
      },
      checkPassword: {
        title: "确认密码",
        holder: "",
        key: "checkPassword",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
        requiredRule: {
          minLength: "6"
        }
      },
      accountType: {
        title: "账号类型",
        holder: "",
        key: "accountType",
        value: "",
        barType: "HZAreaPickerView:file:personType",
        isEnable: true,
        isRequired: true,
      },
      kind: {
        title: "身份类型",
        holder: "",
        key: "kind",
        value: "",
        barType: "HZAreaPickerView:file:kind",
        isEnable: true,
        isRequired: true,
      },
      name: {
        title: "姓名",
        holder: "",
        key: "kind",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      sex: {
        title: "性别",
        holder: "",
        key: "sex",
        value: "",
        barType: "HZAreaPickerView:file:sex",
        isEnable: true,
        isRequired: true,
      },
      qq: {
        title: "QQ",
        holder: "",
        key: "qq",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: false,
      },
      mail: {
        title: "邮箱",
        holder: "",
        key: "mail",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: false,
      },
      provinceAndCity: {
        title: "所属省市",
        holder: "",
        key: "provinceAndCity",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      companyName: {
        title: "公司名称",
        holder: "",
        key: "companyName",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      product: {
        title: "主营产品",
        holder: "",
        key: "product",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      industry: {
        title: "所属行业",
        holder: "",
        key: "industry",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      companyPhone: {
        title: "公司电话",
        holder: "",
        key: "companyPhone",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: false,
      },
      companyFix: {
        title: "公司传真",
        holder: "",
        key: "companyFix",
        value: "",
        barType: "KeyBoardType:number",
        isEnable: true,
        isRequired: false,
      },
      companyAddress: {
        title: "公司地址",
        holder: "",
        key: "companyAddress",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: true,
      },
      companyWWW: {
        title: "公司网址",
        holder: "",
        key: "companyWWW",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: false,
      },
      isntro: {
        title: "公司简介",
        holder: "",
        key: "isntro",
        value: "",
        barType: "KeyBoardType:text",
        isEnable: true,
        isRequired: false,
      },
    },
    isSelectCompany: false
  },

  inputBarValue: function(e) {
    console.log(e);
    var key = e.detail.key;
    var val = e.detail.val;
    if (key.indexOf("accountType") === 0) {
      var isSelectCompany = false;
      if (val.indexOf("公司") === 0) {
        isSelectCompany = true;
      }
      this.setData({
        isSelectCompany: isSelectCompany
      });
    }
    this.data.formData[key].value = val;
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options);
    wx.setNavigationBarTitle({
      title: '完善资料',
    });

    if (options.phone) {
      var newformData = this.data.formData;
      newformData.mobile.value = options.phone;
      this.setData({
        formData: newformData
      });
    }
  },

  user_register1: function(e) {
    var kvstr = kvutil.dic_to_string(this.data.formData);
    console.log("user_register1" + kvstr);
    wx.switchTab({
      url: '../login/login'
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})